using OpenTK;

namespace ColladaDotNet.OpenTKMapping
{
	public class Vertices : DocumentLibraryElement<vertices>, IDoubleArray
	{
		Vector4 IDoubleArray.GetVector4(ulong i)
		{
			if (position != null)
			{
				return position.GetVector4(i);
			}
			return new Vector4(0,0,0,1);
		}

		public Vector3 GetVector3(ulong i)
		{
			if (position != null)
			{
				return position.GetVector3(i);
			}
			return new Vector3();
		}

		public double GetDouble(ulong i)
		{
			if (position != null)
			{
				return position.GetDouble(i);
			}
			return 0.0;
		}

		public ulong Count
		{
			get
			{
				return position.Count;
			}
		}

		private Source position;
		internal override void Load(vertices colladaData)
		{
			base.Load(colladaData);

			foreach (var input in colladaData.input)
			{
				switch (input.semantic)
				{
					case "POSITION":
						position = Document.GetElementByUrl<Source>(input.source);
						break;
				}
			}
		}
	}
}